package com.itts.hk.theard;

import com.itts.common.entity.User;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class test {
    @Test
    public void test1() {
        List<User> list = new ArrayList<>();
        User u1 = new User("xiao", 45, "pp");
        User u2 = new User("zh", 90, "tr");
        User u3 = new User("ty", 100, "yy");
        User u6 = new User("ty", 120, "yy");
        User u4 = new User("ui", 80, "pp");
        User u5 = new User("x", 60, "pp");
        list.add(u1);
        list.add(u2);
        list.add(u3);
        list.add(u4);
        list.add(u5);
        list.add(u6);

        Map<String, User> map = list.stream().collect(Collectors.toMap(User::getIs, t -> t,(s1,s2)->(s1.getAge()>s2.getAge()?s1 :s2)));
        Collection<User> values = map.values();
        System.out.println(values);
    }
}
